home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- * amigados.c: Functions for environment variables, filenames, requestors,
- * and control-C checking.
- * A part of OberSuite for the Commodore Amiga.
- *
- * Author: Daniel Barrett, barrett@cs.umass.edu.
- * Version: 1.0.
- * Copyright: None! This program is in the Public Domain.
- * Please share it with others.
- ***************************************************************************/
-
- #include "decl.h"
-
- /***************************************************************************
- * Functions for environment variables.
- ***************************************************************************/
-
- /*
- * Return the value of an ENV: environment variable "variableName", if it
- * exists.
- */
-
- char *GetEnv(char *variableName)
- {
- char *result = NULL;
-
- DisableRequestors(); /* In case ENV: is non-existent. */
- result = getenv(variableName);
- EnableRequestors();
- return(result);
- }
-
-
- /***************************************************************************
- * Enable and disable system requestors.
- ***************************************************************************/
-
- static APTR oldWindowPtr; /* Pointer to current window. */
- static struct Process *theProc; /* Pointer to current process. */
-
-
- /* Turn off system requestors for this process. */
-
- void DisableRequestors(void)
- {
- theProc = (struct Process *)FindTask(NULL);
- oldWindowPtr = theProc->pr_WindowPtr;
- theProc->pr_WindowPtr = (APTR)(-1L);
- }
-
-
- /*
- * Turn on system requestors for this process, after they have been
- * turned off by DisableRequestors(), above.
- */
-
- void EnableRequestors(void)
- {
- theProc->pr_WindowPtr = oldWindowPtr;
- }
-
- /***************************************************************************
- * Check whether or not control-C has been pressed.
- ***************************************************************************/
-
- /*
- * Was control-C pressed? Return TRUE or FALSE appropriately.
- * In this program, pressing control-C once means terminate the program.
- * So, we use a static variable "ctrl_c_pressed" to store whether or not
- * control-C was EVER pressed, rather than calling SetSignal() repeatedly.
- * (For some reason, SetSignal() seems to clear its signals after being
- * called -- this is not acceptable in our program!)
- */
-
- BOOL CtrlcCheck(void)
- {
- static BOOL ctrl_c_pressed = FALSE;
-
- if (!ctrl_c_pressed)
- ctrl_c_pressed = SetSignal(0L, 0L) & SIGBREAKF_CTRL_C;
-
- return(ctrl_c_pressed);
- }
-
- /***************************************************************************
- * Return the base name of a file. This is a nice, generic function.
- ***************************************************************************/
-
- /* BaseName(filename): Return a pointer to the base name of the file,
- * stripped of its leading directory component (if any).
- * Return NULL if this can't be done.
- * Works OK if:
- *
- * filename == ":" or "/" Returns NULL.
- * filename == "" or NULL Returns NULL.
- * filename ends with ":" or '/' Returns NULL.
- */
-
- char *BaseName(char *filename)
- {
- char *p;
-
- if ((!filename) || (*filename == '\0'))
- return(NULL);
-
- /*
- * Point to the last character of the filename, and walk backwards
- * until we reach a '/' or ':' or the beginning of the filename.
- */
-
- p = filename + strlen(filename) - 1;
-
- while (*p && (p >= filename))
- {
- if ((*p == '/') || (*p == ':'))
- {
- p++;
- break;
- }
- else if (p > filename)
- p--;
- else
- break;
- }
-
- return(*p ? p : NULL);
- }
-